package com.railway.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.service.UserService;
import com.railway.service.impl.UserServiceImpl;
import com.railway.util.JSONUtil;

/**
 * Servlet implementation class RemoveContactServlet
 */
/**用于删除乘车人
 * @author 33676
 *
 */
@WebServlet("/RemoveContactServlet.do")
public class RemoveContactServlet extends HttpServlet {
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("Utf-8");
		int user_id = 0;
		
		String contact_id[] = {};
		
		if(request.getParameter("user_id") != null && !"".equals(request.getParameter("user_id"))) {
			user_id = Integer.parseInt(request.getParameter("user_id"));
		}
		
		if(request.getParameterValues("contact_id[]") != null) {
			contact_id = request.getParameterValues("contact_id[]");
		}
		
		UserService us = new UserServiceImpl();
		
		int temp = 0;
		
		for (int i = 0; i < contact_id.length; i++) {
			us.deleteContact(user_id, Integer.parseInt(contact_id[i]));
			temp ++;
		}
		
		int erroCode = 0;
		if(temp>0) {
			erroCode = 1;
		}
		
		JSONUtil.responJSOn(response, erroCode);
	}

}
